﻿//
// Copyright (c) 2024 BPer
//

#ifndef BPERDECODERBPERVIDEODECODERAndroid_H_
#define BPERDECODERBPERVIDEODECODERAndroid_H_
#include <bperdecoder/BPerAudioDecoderHandles.h>
#include <bperdecoder/BPerVideoDecoder.h>
#include <bperavutil/video/BPerYuvConvert.h>
#include <bperutil/sys/BPerLoadLib.h>
#include <bperutil/BPerAvInfoType.h>


#if BPer_OS_ANDROID
#include <media/NdkMediaCodec.h>

class BPerDecoderMediacodec: public BPerVideoDecoder {
public:
	BPerDecoderMediacodec(BPerVideoInfo *pcontext,BPerVideoCodec pencdectype);
	virtual ~BPerDecoderMediacodec();
	void parseRtmpHeader(uint8_t *p, int32_t pLen, int32_t *pwid, int32_t *phei, int32_t *pfps);
	void init();
	int32_t decode(BPerFrame* videoFrame,BPerYuvType yuvtype,BPerDecoderCallback* pcallback);
	void decode_close();
private:
	BPerVideoCodec m_encDecType;
	BPerVideoInfo *m_context;
	int32_t m_bitDepth;
	int32_t ret;
	BPerBool m_isNv12;

	AMediaCodec* m_mediaCodec;
	uint8_t* m_nv12Buffer;

	int32_t m_width;
	int32_t m_height;
	int32_t m_yuvLen;
	int32_t yLen;
	int32_t uLen;
	int32_t tryagainCount;

	BPerYuvConvert m_yuv;
};
#endif
#endif /* BPERDECODER_SRC_BPERH2645VIDEODECODERFFMPEG_H_ */
